#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define MAXVEX 20

typedef unsigned char VertexType;
typedef unsigned int EdgeType;
typedef struct
{
    VertexType vexs[MAXVEX];
    EdgeType arc[MAXVEX][MAXVEX];
	int numVertexes, numEdges;
}MGraph;

bool visited[MAXVEX] = {false};

VertexType vertexArray[MAXVEX][MAXVEX]={
	   /*0  1  2  3  4  5  6  7  8*/
/* 0 */ {0, 1, 1, 0, 0, 0, 0, 0, 0},
/* 1 */ {1, 0, 0, 1, 1, 1, 0, 0, 0},
/* 2 */ {1, 0, 0, 0, 0, 1, 1, 0, 0},
/* 3 */ {0, 1, 0, 0, 1, 0, 0, 1, 0},
/* 4 */ {0, 1, 0, 1, 0, 0, 0, 1, 0},
/* 5 */ {0, 1, 1, 0, 0, 0, 0, 1, 1},
/* 6 */ {0, 0, 1, 0, 0, 0, 0, 1, 1},
/* 7 */ {0, 0, 0, 1, 1, 1, 1, 0, 1},
/* 8 */ {0, 0, 0, 0, 0, 1, 1, 1, 0}
};

void CreateGraphMatrix(MGraph *G)
{
    for(int i=0; i<G->numVertexes; ++i)
    {
    	for (int j = 0; j < G->numVertexes; ++j)
    	{
    		G->arc[i][j] = vertexArray[i][j];
    	}
    	G->vexs[i] = i;
    }
}


void BFSTraverse(MGraph G)
{
    queue<VertexType> q;
    for (int i = 0; i < G.numVertexes; ++i)
    	visited[i] = false;
    for (int i = 0; i < G.numVertexes; ++i)
    {
    	if (!visited[i])
    	{
    		visited[i] = true;
    		printf("%d ", G.vexs[i]);
    		q.push(i);
    		while(!q.empty())
    		{
    			i = q.front();
    			q.pop();
    			for (int j = 0; j < G.numVertexes; ++j)
    			{
    				if(G.arc[i][j] == 1 && !visited[j])
    				{
    					visited[j] = true;
    					printf("%d ", G.vexs[j]);
    					q.push(j);
    				}
    			}
    		}
    	}
    }
}


int main(int argc, char const *argv[])
{
	MGraph *G = (MGraph*)malloc(sizeof(MGraph));
	G->numVertexes = 9;
	CreateGraphMatrix(G);
	BFSTraverse(*G);
	cout << endl << "Helloworld" << endl;
	return 0;
}
